package pl.bristleback.server.bristle.mocks.actions;

import org.apache.log4j.Logger;
import org.jwebsocket.api.WebSocketConnector;
import org.jwebsocket.token.Token;
import pl.bristleback.server.bristle.actions.AnnotatedRemoteAction;
import pl.bristleback.server.bristle.actions.RemoteAction;
import pl.bristleback.server.bristle.exceptions.handlers.MissingRightsErrorHandler;

import java.util.Set;

/**
 * Action class mock with required rights.
 * <p/>
 * Created on: 2010-11-10 12:43:25 <br/>
 *
 * @author Wojciech Niemiec
 */
@AnnotatedRemoteAction(actionName = MissingRightsHandlingActionMock.ACTION_NAME, requiredRights = {MissingRightsHandlingActionMock.ACTION_RIGHTS})
public class MissingRightsHandlingActionMock implements RemoteAction, MissingRightsErrorHandler {
  private static Logger log = Logger.getLogger(MissingRightsHandlingActionMock.class.getName());

  public static final String ACTION_NAME = "actionNameMock";

  public static final String ACTION_RIGHTS = "admin";

  public static final String HAS_ERROR_FIELD = "hasError";

  public void handleMissingRightsError(Set<String> requiredRights, WebSocketConnector connector, Token token) {
    connector.setBoolean(HAS_ERROR_FIELD, true);
  }

  public void performAction(WebSocketConnector connector, Token token) {
    connector.setBoolean(HAS_ERROR_FIELD, false);
  }
}
